<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <!-- 使⽤ JS 闭包，给 10 个 p 标签循环加上点击事件 -->
    <div>
      <p>0</p>
      <p>1</p>
      <p>2</p>
      <p>3</p>
      <p>4</p>
      <p>5</p>
      <p>6</p>
      <p>7</p>
      <p>8</p>
      <p>9</p>
      <p>10</p>
    </div>
    <script>
      window.onload = () => {
        var arr = document.getElementsByTagName('p')
        function myLoad() {
          for (let i = 0; i < arr.length; i++) {
            arr[i].onclick = function () {
              console.log(i)
            }
          }
        }
        myLoad()
      }
    </script>
  </body>
</html>
